home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Python 1.3.3 / Python 133 SRC / Mac / Modules / res / resedit.py next >
Text File  |  1995-06-18  |  967b  |  42 lines

  1. resource_body = """
  2. char *buf;
  3. int len;
  4. Handle h;
  5.  
  6. if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
  7.     return NULL;
  8. h = NewHandle(len);
  9. if ( h == NULL ) {
  10.     PyErr_NoMemory();
  11.     return NULL;
  12. }
  13. HLock(h);
  14. memcpy(*h, buf, len);
  15. HUnlock(h);
  16. return (PyObject *)ResObj_New(h);
  17. """
  18.  
  19. f = ManualGenerator("Resource", resource_body)
  20. f.docstring = lambda: """Convert a string to a resource object.
  21.  
  22. The created resource object is actually just a handle.
  23. Apply AddResource() to write it to a resource file.
  24. """
  25. functions.append(f)
  26.  
  27. # Convert resources to other things.
  28.  
  29. as_xxx_body = """
  30. return %sObj_New((%sHandle)_self->ob_itself);
  31. """
  32.  
  33. def genresconverter(longname, shortname):
  34.  
  35.     f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname))
  36.     docstring =  "Return this resource/handle as a %s"%longname
  37.     f.docstring = lambda docstring=docstring: docstring
  38.     return f
  39.  
  40. resmethods.append(genresconverter("Control", "Ctl"))
  41. resmethods.append(genresconverter("Menu", "Menu"))
  42.